package cn.hbu.zlfw.common.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import cn.hbu.zlfw.exchange.entity.Replier;
import cn.hbu.zlfw.patent.entity.PatentApply;
import cn.hbu.zlfw.patent.entity.PatentSynergy;

/**
 * 
 * @ClassName: DateSortUtil
 * @Description: 时间排序相关工具类
 * @author 王鹏伟<1223443289@qq.com>
 * @date 2017年12月16日 下午9:11:11 
 * @vsersion:v1.0
 */
public class DateSortUtil {
	
	
	/**
	 * 
	 * @Title: sortSynergyByCTimeDEC 
	 * @Description: 按创建时间递减对专利协作申请书列表进行排序
	 * @return List<PatentSynergy> 
	 * @throws
	 */
	public static List<PatentSynergy> sortSynergyByCTimeDEC(Set<PatentSynergy> patentSynergies){
		List<PatentSynergy> patentSynergies2 = new ArrayList<PatentSynergy>();
		for (PatentSynergy patentSynergy : patentSynergies) {
			patentSynergies2.add(patentSynergy);
		}
		//冒泡排序：按时间递减排序
		boolean flag = false;
		PatentSynergy temp = null;
		for (int i = 0; i < patentSynergies2.size()-1; i++) {
			flag = true;
			for (int j = 0; j < patentSynergies2.size()-1-i; j++) {
				if(patentSynergies2.get(j).getCreateTime().before(patentSynergies2.get(j+1).getCreateTime())) {
					flag = false;
					temp = patentSynergies2.get(j);
					patentSynergies2.set(j, patentSynergies2.get(j+1));
					patentSynergies2.set(j+1, temp);
				}
			}
			if(flag) {
				break;
			}
		}
		return patentSynergies2;
	}
	/**
	 * 
	 * @Title: sortApplyByCTimeDEC 
	 * @Description: 按创建时间递减对专利协作申请书列表进行排序
	 * @return List<PatentSynergy> 
	 * @throws
	 */
	public static List<PatentApply> sortApplyByCTimeDEC(Set<PatentApply> patentApplies){
		List<PatentApply> patentApplies2 = new ArrayList<PatentApply>();
		for (PatentApply patentApply : patentApplies) {
			patentApplies2.add(patentApply);
		}
		//冒泡排序：按时间递减排序
		boolean flag = false;
		PatentApply temp = null;
		for (int i = 0; i < patentApplies2.size()-1; i++) {
			flag = true;
			for (int j = 0; j < patentApplies2.size()-1-i; j++) {
				if(patentApplies2.get(j).getCreateTime().before(patentApplies2.get(j+1).getCreateTime())) {
					flag = false;
					temp = patentApplies2.get(j);
					patentApplies2.set(j, patentApplies2.get(j+1));
					patentApplies2.set(j+1, temp);
				}
			}
			if(flag) {
				break;
			}
		}
		return patentApplies2;
	}
	
	/**
	 * 
	 * @Title: sortReplyByCTimeASC 
	 * @Description: 按创建时间递增对留言板子贴进行排序
	 * @return List<PatentSynergy> 
	 * @throws
	 */
	public static List<Replier> sortReplyByCTimeASC(Set<Replier> repliers){
		List<Replier> repliers2 = new ArrayList<Replier>();
		for (Replier replier : repliers) {
			repliers2.add(replier);
		}
		//冒泡排序：按时间递减排序
		boolean flag = false;
		Replier temp = null;
		for (int i = 0; i < repliers2.size()-1; i++) {
			flag = true;
			for (int j = 0; j < repliers2.size()-1-i; j++) {
				if(!repliers2.get(j).getCreateTime().before(repliers2.get(j+1).getCreateTime())) {
					flag = false;
					temp = repliers2.get(j);
					repliers2.set(j, repliers2.get(j+1));
					repliers2.set(j+1, temp);
				}
			}
			if(flag) {
				break;
			}
		}
		return repliers2;
	}
	
	
	
}
